package com.gate.way.demo.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

/**
 * @author wangzhilong
 * @date 2021/3/18
 */
@Component
@Order(200)
public class LogFilter implements WebFilter {
    final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        //用于传递数据
        final Object name = exchange.getAttribute("name");
        logger.info("消息打印拦截器：{}",name);
        return chain.filter(exchange);
    }
}
